﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace gChartSharp
{
    public class RangeMarkerParam : ParamBase<RangeMarker>, IRenderable
    {
        public override string Name { get { return "chm"; } }

        protected override char ParamSeparator { get { return '|'; } }
    }


    public class RangeMarker : IRenderable
    {
        /// <summary>
        /// The type of marker
        /// </summary>
        public RangeMarkerType RangeMarkerType { get; set; }


        /// <summary>
        /// The color of the marker
        /// </summary>
        public Color Color { get; set; }


        /// <summary>
        /// Starting point - value must be between 0.00 and 1.00
        /// </summary>
        public float StartPoint 
        {
            get { return mStartPoint; }
            set 
            {
                if (value >= 0 && value <= 1)
                    mStartPoint = (float)Math.Round(value, 2);
                else
                    throw new ParamException("StartPoint must be between 0.00 and 1.00");
            } 
        }
        private float mStartPoint;


        /// <summary>
        /// Ending point - value must be between 0.00 and 1.00
        /// </summary>
        public float EndPoint
        {
            get { return mEndPoint; }
            set
            {
                if (value >= 0 && value <= 1)
                    mEndPoint = (float)Math.Round(value, 2);
                else
                    throw new ParamException("EndPoint must be between 0.00 and 1.00");
            }
        }
        private float mEndPoint;


        /// <summary>
        /// Constructor to initialize all properties
        /// </summary>
        /// <param name="rangeMarkerType"></param>
        /// <param name="color"></param>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        public RangeMarker(RangeMarkerType rangeMarkerType, Color color, float startPoint, float endPoint)
        {
            RangeMarkerType = rangeMarkerType;
            Color = color;
            StartPoint = startPoint;
            EndPoint = endPoint;
        }

        public string Render()
        {
            return String.Format("{0},{1},0,{2},{3}", (char)RangeMarkerType, Color.ToHtml(), StartPoint, EndPoint);
        }
    }


    public enum RangeMarkerType
    {
        Horizontal = 'r',
        Vertical = 'R'
    }
}
